package com.ms.oschina.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;

import com.ms.oschina.api.remote.OsChinaApi;
import com.ms.oschina.base.BaseViewHolder;
import com.ms.oschina.bean.Constants;
import com.ms.oschina.bean.Event;
import com.ms.oschina.fragment.ActivitiesFragment;
import com.ms.oschina.fragment.ActivitiesInfoFragment;
import com.ms.oschina.ui.activity.EventDetailsActivity;
import com.ms.oschina.util.PreferenceUtils;
import com.ms.oschina.util.UiUtils;
import com.ms.oschina.viewholder.EventViewHolder;

public class ActivitiesAdapter extends PageIndexListAdapter<Event> {

	public ActivitiesAdapter(AbsListView listView, List<Event> list,
			boolean loadMore) {
		super(listView, list, loadMore);
	}

	@Override
	public void onNormalItemClick(AdapterView<?> parent, View view,
			int position, long id) {
		Event event = getListData().get(position);
		// // 开启新闻详情界面
		Context context = UiUtils.getContext();

		Intent intent = new Intent(context, EventDetailsActivity.class);
		intent.putExtra(Constants.EVENTDETAILS_ID, event.getId());
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(intent);
	}

	@Override
	public BaseViewHolder<Event> getItemViewHolder() {
		EventViewHolder EventViewHolder = new EventViewHolder();
		return EventViewHolder;
	}

	@Override
	public void getHolder(BaseViewHolder<Event> holder) {
		EventViewHolder viewHolder = (EventViewHolder) holder;
		int mark = getMark();
		viewHolder.setMark(mark);
	}

	@Override
	public List<Event> getLoadMoreData() throws Exception {
		int mark = getMark();

		List<Event> list = null;
		int uid = 0;
		switch (mark) {
		case ActivitiesFragment.NEW_EVENT:
			list = OsChinaApi.getActivitiesList(pageIndex, uid);
			break;
		case ActivitiesFragment.MY_EVENT:
			uid = PreferenceUtils.getPrefInt(UiUtils.getContext(),
					Constants.UID, 1);
			list = OsChinaApi.getActivitiesList(pageIndex, uid);
			break;
		}

		return list;
	}

}
